import React,{Suspense} from 'react'
import{
    BrowserRouter,
    Route,
    Routes,
    Navigate  //Navigate导航
} from 'react-router-dom'
import router from './routerConfig'
interface ROUERS{
    path?:string,
    to?:string,
    component?:any,
    children?:ROUERS[],

}   


export default function routerViton() {
    const stouterData = ((store:ROUERS[])=>{
        return store.map((item,index)=>{
            return <Route path={item.path} key={index} element={item.to ? <Navigate to={item.to} /> : <item.component/> } >
                {
                    item.children && stouterData(item.children)
                }

            </Route>
        })
    })
  return (
    <BrowserRouter>
        <Suspense>
            <Routes>
                {
                    stouterData(router)
                }
            </Routes>
        </Suspense>
    </BrowserRouter>
  )
}
